package managment;

import java.util.ArrayList;
import java.util.Random;

/**
 * finished-tested testing level: weak (1 test case)
 */
@SuppressWarnings("unchecked")
public class Auto extends ArraySource{

	Prop prop;
	int crtSeed;
	Random generator;
	boolean [] flag;
	int maxVal = 50;
	private int size;
	
	
	protected Auto(int arraySize, Object obj) {
		super(arraySize, obj);
		this.size=arraySize;
		this.prop=(Prop)obj;
		this.generator=new Random();
		this.flag=new boolean[arraySize];
	}
	

	@Override
	public ArrayList<Comparable[]> createTarget() {
		
		Comparable[] crtList=new Comparable[size];
		
//		while(prop!=null && this.size>0){
			
			super.product.add(crtList);
			
			switch (this.prop){
			
				case random:
				{
					for (int i = 0; i < crtList.length; i++) {
						int tempIdx=this.generator.nextInt(crtList.length);
						crtList[tempIdx]=new Integer(this.generator.nextInt(this.maxVal));
						flag[tempIdx]=true;
					}
					for (int i = 0; i < crtList.length; i++) {
						if(!this.flag[i]){
							this.flag[i]=true;
							crtList[i]=new Integer(this.generator.nextInt(this.maxVal));
						}
					}
					break;
				}
				case sorted:
				{
					int upper=0, lower;
					for (int i = 0; i < crtList.length; i++) {
						lower = upper;
						upper += (i+1)*10;
						crtList[i]=new Integer((int)(Math.random()*(upper-lower)+lower));
					}
					break;
				}
				case invSorted:
				{
					int upper=0, lower=(crtList.length)*20;
					for (int i = 0; i < crtList.length; i++) {
						upper = lower;
						lower -=(20*crtList.length-i);
						crtList[i]=new Integer((int)(Math.random()*(upper-lower)+lower));
					}
					break;
				}
				default: 	
				{
					break;
				}	
			}
//		}
		return super.product;
	}


	/**
	 * @param crtSeed  the crtSeed to set
	 * @uml.property  name="crtSeed"
	 */
	public void setCrtSeed(int crtSeed) {
		this.crtSeed = crtSeed;
	}


	/**
	 * @param prop  the prop to set
	 * @uml.property  name="prop"
	 */
	public void setProp(Prop prop) {
		this.prop = prop;
	}

}
